#define _CRT_SECURE_NO_WARNINGS 1



#include<iostream>
using namespace std;
int main()
{
    int n, m;
    char ch = ' ';
    cin >> n >> m;
    //char arr[n][m];
    char arr[1001][1001];
    int x = 0, y = 0;
    for (int i = 0;i < n;i++)
    {
        for (int j = 0;j < m;j++)
        {
            cin >> arr[i][j];
            if (arr[i][j] >= 'A' && arr[i][j] <= 'Z')
            {
                ch = arr[i][j];
                x = i;
                y = j;
            }
        }
    }
    int sum = 0;
    if (ch == 'W')
    {
        for (int i = x - 1;i >= 0;i--)
        {
            if (arr[i][y] == '*')
                sum++;
        }
    }
    else if (ch == 'A')
    {
        for (int j = y - 1;j >= 0;j--)
        {
            if (arr[x][j] == '*')
                sum++;
        }
    }
    else if (ch == 'S')
    {
        for (int i = x + 1;i < n;i++)
        {
            if (arr[i][y] == '*')
                sum++;
        }
    }
    else if (ch == 'D')
    {
        for (int j = y + 1;j < m;j++)
        {
            if (arr[x][j] == '*')
                sum++;
        }
    }
    cout << sum;
    return 0;
}